home *** CD-ROM | disk | FTP | other *** search
- Path: EU.net!sun4nl!xs4all!falstaff
- From: falstaff@xs4all.nl (Falstaff)
- Newsgroups: comp.lang.c
- Subject: Re: NEwbie: How to return a multi-dimensional array from function?
- Date: 15 Mar 1996 15:53:07 GMT
- Organization: XS4ALL, networking for the masses
- Message-ID: <4ic3p3$cl5@news.xs4all.nl>
- References: <4hp273$8bu@news.xs4all.nl> <31404CE9.1A4A@mc.net> <mjs.826298629@hubcap> <4ib78s$6gv@news.bridge.net>
- NNTP-Posting-Host: xs1.xs4all.nl
- X-Newsreader: NN version 6.5.0 #666 (NOV)
-
- psycho@bridge.net (Gary Thompson) writes:
-
- >>Two things: (1) If you are going to use the value of tmp outside of Foo(),
- >>then you need to declare
- >> static tmp[10][5];
- >>Otherwise the storage may disappear when you return from Foo().
-
- >No, declaring it as static will only retain the value in the foo() function, if
- >you call it more than once. You CANNOT use a value declared in a subfunction in
- >MAIN. You would have to remove both TMP declarations from MAIN and FOO and
- >declare the thing globally outside of main.
-
- WRONG!!!
-
- If you declare a function
-
- int *demo(void)
- { static int n=0;
- n++;
- return &n;
- }
-
- the caller can use the static variable until the next time your function
- is called. This is how the standard library function tmpnam() returns,
- for example.
-
- Frank
- --
- The famous GIICM now on line: http://www.xs4all.nl/~falstaff/GIICM.html
- ------------------------------------------------------------------------
- Frank A. Vorstenbosch +31-(70)-355 5241 falstaff@xs4all.nl
-